from django.db import models
from django import forms
from django.forms import ModelForm
from django.contrib.syndication.views import Feed

# Create your models here.
class PostModel(models.Model):
    GENDER_CHOICES = (              
        ('M', 'Male'),
        ('F', 'Female'),
    )

    gender = models.CharField(max_length=1,choices=GENDER_CHOICES,blank=False,default='M')
    #about = models.CharField(max_length=100)
    #author = models.CharField(max_length = 25)
    adjective = models.CharField(max_length = 15)
    noun = models.CharField(max_length = 15)
    whileyou = models.CharField(max_length=40)
    description = models.TextField()
    five = models.IntegerField()
    low= models.IntegerField()
    datestamp = models.DateTimeField()
    approve = models.BooleanField()
    comments = models.IntegerField()
    campus = models.CharField(max_length=15)
    campus_aff = models.BooleanField()
    
    def get_absolute_url(self):
        return "http://www.while-you-were.com/wyw/"+str(self.id)
class PostForm(ModelForm):
    class Meta:
        model = PostModel 
        exclude = ('datestamp','five','low','approve','comments') 
        widgets= {'whileyou': forms.TextInput(attrs={'place': 'While you were...','size':'40','label':'While you were','class':'inputText','require':'True'}),
                  'adjective':forms.TextInput(attrs={'place':'adjective','size':'15','label':'Adjective','require':'True'}),
                  'campus':forms.TextInput(attrs={'place':'campus','size':'15','label':'Campus'}),
                  'noun':forms.TextInput(attrs={'place':'noun','size':'15','label':'Noun','require':'True'}),
                  'description':forms.Textarea(attrs={'cols':'48','label':'Description','require':'True','class': 'formtext'})}
        
class Intro(models.Model):
    description = models.TextField()
    
class Comment(models.Model):
    post = models.IntegerField()
    comment = models.TextField()
    author = models.CharField(max_length=30)
    datestamp = models.DateTimeField()
    approve = models.BooleanField()
class CommentForm(ModelForm):
    class Meta:
        model = Comment
        exclude = ('post','datestamp')
        
class LatestPosts(Feed):
    title = "WhileYouWere Confessions"
    link = "http://www.while-you-were.com/"
    description = "Newest Confessions while you were [insert-action-here]"

    def items(self):
        return PostModel.objects.order_by('-datestamp')[:10]

    def item_title(self, item):
        return 'While you were ' + item.whileyou

    def item_description(self, item):
        if not item.campus_aff:
            campus = " at " + item.campus
        else:
            campus = ""
        return "[Posted by " + item.gender + " about " + item.adjective + " " + item.noun + campus + "]\n" + item.description
    
    def item_pubdate(self, item):
        return item.datestamp
 